import { ApiProperty, PartialType } from '@nestjs/swagger';
import {
  PartialType as NestMappedPartialType,
  OmitType,
} from '@nestjs/mapped-types';
import { IdValidator } from '../decorators/dto.decorator';
import { Optional } from '@nestjs/common';

export enum AssetType {
  MODULE = 'module', //模块
  MENU = 'menu', //菜单
  FEATURE = 'feature', //功能 操作按钮
}

export class CreateAssetDto {
  @ApiProperty({ description: '资源名称', example: 'name' })
  name: string;

  @ApiProperty({ description: '资源类型', example: '菜单' })
  type: AssetType;

  @ApiProperty({ description: '资源地址', example: '/admin/user-list' })
  url: string;

  @ApiProperty({ description: '父权限id', example: 1 })
  parentId: number;

  @ApiProperty({ description: '资源描述', example: '资源描述' })
  description: string;

  @ApiProperty({ description: '启用状态', example: 1 })
  status: number;

  @ApiProperty({ description: '排序编号', example: 1 })
  sort: number;
}

export class UpdateAssetDto extends PartialType(
  OmitType(NestMappedPartialType(CreateAssetDto), []),
) {
  @IdValidator()
  id: number;

  @ApiProperty({ description: '父权限id', example: 1 })
  @Optional()
  parentId: number;
}
